{extend name="base/base" /}
{block name="main"}
<style>
.layui-form-pane .layui-form-label{width: 130px;}
.layui-form-pane .layui-input-block{
        margin-left: 130px;
}
</style>
<form id="form" method="post" class="layui-form layui-form-pane" action="{:url('/admin/sysconfig-addoutlink')}">
	
    <div class="layui-form-item">
        <label class="layui-form-label"><span style="color:red;">*&nbsp;</span>分类</label>
        <div class="layui-input-block">
            <select name="cate_id" lay-filter="cate_id" lay-verify="required">
                {volist name="cate_list" id="vo"}
                <option {notempty name="list"}{eq name="list['cate_id']" value="$vo['id']"}selected=""{/eq}{/notempty} value="{$vo['id']}">{$vo.title}</option>
                {/volist}
            </select>
        </div>
    </div>
	
    <div class="layui-form-item">
        <label class="layui-form-label"><span style="color:red;">*&nbsp;</span>名称</label>
        <div class="layui-input-block">
            <input type="text" name="title" placeholder="请输入" autocomplete="off" class="layui-input"
                   value="{:isset($list.title)?$list.title:''}" {if condition="isset($list['id'])" }lay-verify="required"{else /}
            lay-verify="required|username"{/if}>
        </div>
    </div>
	<div class="layui-form-item">
        <label class="layui-form-label"><span style="color:red;">*&nbsp;</span>链接</label>
        <div class="layui-input-block">
            <input type="text" name="url" placeholder="请输入以'http'或'https'开头的网址" autocomplete="off" class="layui-input"
                   value="{:isset($list.url)?$list.url:''}" lay-verify="required">
        </div>
    </div>
    
    <div class="layui-form-item">
        <div class="layui-input-block">
            <input type="hidden" name="id" value="{:isset($list['id'])?$list['id']:''}">
            <input type="hidden" name="__token__" id="token" value="{$Request.token}"/>
            <button class="layui-btn" lay-submit lay-filter="*">立即提交</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>
</form>
{/block}
{block name="script"}
{css href="/form-select/formSelects-v4.css" /}
<script>
    layui.config({
        base: '/form-select/' //此处路径请自行处理, 可以使用绝对路径
    }).extend({
        formSelects: 'formSelects-v4'
    });
    layui.use(['form', 'jquery', 'formSelects','upload'], function () {
        var formSelects = layui.formSelects, form = layui.form, $ = layui.jquery,upload = layui.upload;
        
        //上传头像
		upload.render({
			elem: '.userFaceBtn',
			url: "{:url('/admin/upload')}",
			accept:'images',
			acceptMime:'image/*',
			done: function(data){
				var icon=5;
				if(!data.code){
					icon=6;
					$('#userFace').attr('src',data.data.src);
					$('#head').val(data.data.src);
				}
				layer.msg(data.msg, {icon:icon,time: 1500});
			},
			error: function(){
				layer.msg('上传失败', {icon:icon,time: 1500});
			}
		});
		
        formSelects.on('selectId', function (id, vals, val, isAdd, isDisabled) {
            $('#group_id').val(layui.formSelects.value(id, 'val'));
        }, true);
        //表单验证
        form.verify({
            username: function (value, item) { //value：表单的值、item：表单的DOM对象
                var msg;
                $.ajax({
                    async: false,
                    url: "{:url('/admin/sysconfig-checkoutlink')}",
                    data: {title: value},
                    success: function (data) {
                        if (data.code== 0) {
                            msg = data.msg;
                        }
                    }
                });
                return msg;
            },
            uploadimg:function(value, item){
                if(!value){
                    return '请上传图片';
                }
            }
        });
        //表单提交
        form.on("submit(*)", function (data) {
            var obj = $(this);
            obj.attr("disabled", "disabled").addClass("layui-disabled");
            $.post(data.form.action, data.field, function (data) {
                var icon = 5;
                if (data.code) {
                    icon = 6;
                }
                layer.msg(data.msg, {icon: icon, time: 1500}, function () {   //提示的插件，可以使用alert代替
                    if (data.code) {
                        setTimeout(function () {
                            //刷新父页面
                            parent.location.reload();
                        }, 500);
                    } else {
                        $('#token').val(data.data.token);
                        obj.removeAttr("disabled").removeClass("layui-disabled");
                    }
                });
            }, 'json');
            return false;
        });
    });


</script>
{/block}